﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ajayumi.develop.win32.Transport.Client.WinForm.Controls;
using ajayumi.develop.win32.Transport.WCF.Services;

namespace ajayumi.develop.win32.Transport.Client.WinForm
{
    public partial class FolderBrowserDlg : Form
    {

        #region property

        public string SelectedPath
        {
            get
            {
                return this.ucDriveTree1.Path;
            }
        }

        public bool IsDirectory
        {
            get
            {
                return this.ucDriveTree1.IsDirectoryNode;
            }
        }

        public List<FilePathInfo> DriveNodeList
        {
            get
            { return this.ucDriveTree1.DriveNodeList; }
        }

        #endregion

        public FolderBrowserDlg()
        {
            InitializeComponent();
        }


        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            this.ucDriveTree1.AsyncLoad();
        }

        private void SetEnable(Button btn, bool value)
        {
            if (btn.InvokeRequired)
            { btn.Invoke(new Action<Button, bool>(SetEnable), new object[] { btn, value }); }
            else
            { btn.Enabled = value; }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void btnCreateFolder_Click(object sender, EventArgs e)
        {

        }

        private void directoryTree1_BeginLoad(object sender, EventArgs e)
        {
            this.SetEnable(this.btnCreateFolder, false);
            this.SetEnable(this.btnSubmit, false);
        }

        private void directoryTree1_LoadCompleted(object sender, AsyncCompletedEventArgs e)
        {
            this.SetEnable(this.btnCreateFolder, true);
            this.SetEnable(this.btnSubmit, true);
        }

    }
}
